vcCommand

Object type for commands that can be executed using Python API and made available in user interface of application.

See in: Overview

Module: vcCore

Parent: vcObject

Children -

Referenced by: vcCore.getCommand()

Properties

Learn how to use properties here. The properties are also inherited from the parent class.

NameTypeAccessDescription
CommandsvcListRGets the list of Python 3 commands.
FilePathStringRGets the source file path.
FolderPathPathRGets the source folder path.
IsEnabledBooleanRWGets or sets the flag defining if the command is enabled in the user interface.
NameStringRWGets or sets command's name
PropertiesvcPropertyContainerRGets the properties of this command.

Methods

Learn how to use methods here. The methods are also inherited from the parent class.

NameReturn TypeParametersDescription
addMenuItemNoneString menuName,
String caption,
Optional Keyword[position = Integer],
Optional Keyword[tooltip = String],
Optional Keyword[iconPath = String],
Optional Keyword[referenceId = String],
Optional Keyword[controlType = vcMenuTool]
Adds this command to a menu.
See more
Parameters:
menuName (String): Target menu name.
caption (String): A caption to display.
Optional: position (Integer): Where the menu item will be added in the given menu.
Any value less than zero is indexed from the end of the menu. By default, a new menu item is appended to the end of a menu.
Optional: tooltip (String): A tooltip text to display.
Optional: iconPath (String): An icon to display. This can either be an absolute path or relative to "Icons" folder in the installation directory.
Optional: referenceId (String): Refers to another menu item by its command name or id. Generally, you would use this to add items to a gallery menu on the Ribbon in which both the gallery and its items are created using the same Python command.
Optional: controlType (vcMenuTool): Specifies the control type of the menu item.

Exceptions:
RuntimeError: When the command has no name set or name is not unique.

See menuName's
createCommandvcCommandString filePathCreates a new Python 3 command from a given file path.
See more
Parameters:
commandPath (String): Command file path.

Exceptions:
RuntimeError: When failing to read the file from the given path.

Returns:
vcCommand: Created command.
executeNoneNoneCalls 'OnExecute' function on this command.
findCommandvcCommandString argFinds a Python 3 command with a given name.
See more
Parameters:
name (String): Command name.

Returns:
vcCommand: Command if found, None otherwise.

Example: Simple Command Template

""" Template for a simple command with no property panel."""

import vcCore as vc

app = vc.getApplication()
cmd = vc.getCommand()

def OnInit():
  # Executed only once at init
  cmd.Name = "Py3Test"
  cmd.addMenuItem('VcTabHome/Python3', "Py3Test")
  
def OnExecute():
  print('Py3Test')

Example: Command with Panel

""" Template for a command with a property panel with one custom property and 'Apply' & 'Close' buttons."""

import vcCore as vc

app = vc.getApplication()
cmd = vc.getCommand()


def OnInit():
  # Executed only once at init
  cmd.Name = "Py3PanelTest"
  cmd.addMenuItem('VcTabHome/Python3', "Py3PanelTest")


def OnExecute():
  panel.showCommand(cmd)


def on_cancel():
  print ("Canceled.")


def on_apply():
  print('Apply')
  return True


def on_close():
  print("Close")
  return True


def on_prop_changed(args):
  print('New value for S1: ' + prop_s1.Value)


prop_s1 = cmd.Properties['S1']
if prop_s1 == None:
  prop_s1 = cmd.Properties.create(vc.vcPropertyType.STRING, 'S1')
prop_s1.OnChanged += on_prop_changed

panel = vc.vcCommandPanel.new()
panel.Title = "Python 3 Panel Test"
panel.setOnCancel(on_cancel)

btnApply = panel.createButton("Apply", on_apply)
btnApply.IsEnabled = True

btnClose = panel.createButton("Close", on_close)
btnClose.IsEnabled = True

Example: Add Icon to Command

"""
Adding an icon ('MyCommandIcon.svg') to a command.
"""

def OnInit():
  cmd.Name = 'My_Command'
  my_icon_path = os.path.join(cmd.FolderPath, 'MyCommandIcon.svg')
  vc.vcCommand.addMenuItem(cmd,'VcTabHome/MyCommandGroup','My_Command', iconPath = my_icon_path)